﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SimpleServiceBus.EndpointMonitor.Web.Helpers.Flot;

namespace SimpleServiceBus.EndpointMonitor.Web.Models
{
    public class EndpointMetricViewData : FlotChartViewData
    {
        private string _baseUrl = "/Analytics/TimeSeries";

        public string EndpointID { get; set; }
        public string[] Metrics { get; set; }
        public DateTime? StartTime { get; set; }
        public DateTime? EndTime { get; set; }

        public string BaseUrl
        {
            get { return _baseUrl;}
            set { _baseUrl = value;}
        }

        public override string DataUrl
        {
            get
            {
                string url = EndpointID + _baseUrl + "?metrics=" + String.Join(",", Metrics);
                if (StartTime != null)
                    url += "&startTime=" + HttpUtility.UrlEncode(StartTime.Value.ToString());
                if (EndTime != null)
                    url += "&endTime=" + HttpUtility.UrlEncode(EndTime.Value.ToString());

                return url;
            }
            set
            {
                throw new InvalidOperationException(
                    "The DataUrl is automatically generated by the EndpointMetricViewData, and should not be set directly.");
            }
        }
        
    }
}
